<!--
 * @Author: 小花
 * @Date: 2022-03-06 13:10:33
 * @LastEditors: 小花
 * @LastEditTime: 2022-04-18 16:25:01
 * @Description: 
-->
<template>
  <div class='el-menu_container'>
    <el-menu :default-active="defaultActive" mode="horizontal" :ellipsis="false" class="el_menu"
      router>
      <div class="user_info_box">
        <div class="avatar-container">
          <el-avatar :src="userInfo.headimgurl" class="user-avatar">
            <i class="fa fa-user" aria-hidden="true"></i>
          </el-avatar>
          <div class="user-status-indicator"></div>
        </div>
        <div class="user-details">
          <div class="userInfo">
            <span class="nickname"> {{userInfo.nickname || '用户'}} </span>
            <span class="loginType"> {{swapLoginType}} </span>
          </div>
        </div>
        <div class="menu-items">
          <el-menu-item v-for="(item, index) in el_menu_item" :key="'menu-item-'+index" :index="item.index">
            <template #title>
              {{item.name}}
            </template>
          </el-menu-item>
        </div>
      </div>
      <div class="logOut" @click="logOut">
        <i class="fa fa-sign-out" aria-hidden="true"></i>
        <span>安全退出</span>
      </div>
    </el-menu>
  </div>
</template>

<script>
//这里可以导入其他文件（比如：组件，工具js，第三方插件js，json文件，图片文件等等）
//例如：import 《组件名称》 from '《组件路径》';
import { clearLoginInfo, getUserInfo } from '@/js/public'

export default {
  //import引入的组件需要注入到对象中才能使用
  components: {},
  props: ['el_menu_item'],
  data () {
    //这里存放数据
    return {
      userInfo: { ...getUserInfo() },
    }
  },
  //监听属性 类似于data概念
  computed: {
    getCurrentRouter () {
      return this.$route.fullPath
    },
    swapLoginType () {
      switch (this.userInfo.loginType) {
        case 'user':
          return '普通用户'
        case 'worker':
          return '维修员'
        default:
          return '未知'
      }
    },
    defaultActive () {
      return this.$route.path;
    }
  },
  //方法集合
  methods: {
    logOut () {
      clearLoginInfo();
      this.$router.replace({ name: "AccountLogin", replace: true })
    },
  }
}
</script>

<style lang='scss' scoped>
.el-menu_container {
  .el_menu {
    // 导航栏背景色 - 现代渐变
    background: linear-gradient(90deg, #3a7bd5, #00d2ff);
    height: 64px;
    align-items: center;
    justify-content: space-between;
    padding: 0 25px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
    
    .user_info_box {
      display: flex;
      align-items: center;
      height: 100%;
      
      .avatar-container {
        position: relative;
        margin-right: 18px;
        
        .user-avatar {
          border: 2px solid rgba(255, 255, 255, 0.85);
          background-color: #4e8cff;
          box-shadow: 0 4px 10px rgba(0, 0, 0, 0.15);
          transition: all 0.3s;
          
          &:hover {
            transform: scale(1.08);
            border-color: #fff;
            box-shadow: 0 6px 15px rgba(0, 0, 0, 0.2);
          }
        }
        
        .user-status-indicator {
          position: absolute;
          width: 12px;
          height: 12px;
          background-color: #42d279;
          border-radius: 50%;
          bottom: 0;
          right: 0;
          border: 2px solid #fff;
          box-shadow: 0 0 0 2px rgba(66, 210, 121, 0.2);
          animation: pulse 2s infinite;
        }
        
        @keyframes pulse {
          0% {
            box-shadow: 0 0 0 0 rgba(66, 210, 121, 0.4);
          }
          70% {
            box-shadow: 0 0 0 6px rgba(66, 210, 121, 0);
          }
          100% {
            box-shadow: 0 0 0 0 rgba(66, 210, 121, 0);
          }
        }
      }
      
      .user-details {
        margin-right: 35px;
      }
      
      .userInfo {
        display: flex;
        flex-direction: column;
        line-height: normal;
        
        .nickname {
          color: #FFFFFF;
          font-weight: 600;
          font-size: 16px;
          margin-bottom: 5px;
          text-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
          letter-spacing: 0.3px;
        }
        
        .loginType {
          background: rgba(255, 255, 255, 0.25);
          backdrop-filter: blur(4px);
          border-radius: 20px;
          font-size: 12px;
          padding: 3px 10px;
          color: #FFFFFF;
          font-weight: 500;
          box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
        }
      }
      
      .menu-items {
        display: flex;
        height: 100%;
      }
    }
    
    .logOut {
      display: flex;
      align-items: center;
      font-size: 14px;
      cursor: pointer;
      color: #FFFFFF;
      padding: 8px 16px;
      border-radius: 20px;
      transition: all 0.3s;
      font-weight: 500;
      background: rgba(255, 255, 255, 0.1);
      backdrop-filter: blur(4px);
      border: 1px solid rgba(255, 255, 255, 0.2);
      
      i {
        margin-right: 8px;
        font-size: 15px;
      }
      
      &:hover {
        background-color: rgba(255, 255, 255, 0.25);
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
        transform: translateY(-2px);
      }
      
      &:active {
        transform: translateY(0);
      }
    }
    
    :deep(.el-menu-item) {
      color: #FFFFFF !important;
      font-size: 15px;
      height: 64px;
      line-height: 64px;
      padding: 0 22px;
      position: relative;
      transition: all 0.3s;
      font-weight: 500;
      letter-spacing: 0.3px;
      
      &::before {
        content: '';
        position: absolute;
        bottom: 0;
        left: 50%;
        transform: translateX(-50%);
        width: 0;
        height: 3px;
        background-color: #FFFFFF;
        border-radius: 3px 3px 0 0;
        transition: width 0.3s ease;
      }
      
      &:hover {
        background-color: rgba(255, 255, 255, 0.15) !important;
        
        &::before {
          width: 20px;
        }
      }
      
      &.is-active {
        color: #FFFFFF !important;
        font-weight: bold;
        background-color: rgba(255, 255, 255, 0.2) !important;
        
        &::before {
          width: 40px;
          height: 4px;
          background-color: #FFFFFF;
        }
      }
    }
  }
}

// 添加响应式样式
@media screen and (max-width: 768px) {
  .el-menu_container {
    .el_menu {
      padding: 0 15px;
      
      .user_info_box {
        .user-details {
          margin-right: 15px;
        }
        
        .menu-items {
          :deep(.el-menu-item) {
            padding: 0 12px;
          }
        }
      }
      
      .logOut {
        padding: 6px 10px;
        
        span {
          display: none;
        }
      }
    }
  }
}
</style>